"""
目录漫游
1. os.walk
2. 递归
"""
import json
import os


# datas = os.walk("../venv")
# # print(datas)
# for data in datas:
#     # 第一个元素是当前路径  第二个参数是当前路径下放的文件夹  第三个参数是当前路径下方的文件
#     print(data[0], data[1], data[2], "---------------")


# def find(path):
#     for p in os.listdir(path):
#         file_path = os.path.join(path, p)
#         if os.path.isfile(file_path):
#             print(p)
#         else:
#             find(file_path)
#
# find("../venv")


# json序列化时，可以处理的数据类型有哪些？如何定制支持datetime类型？

# import json
# from datetime import datetime
#
# obj = [{
#     "id": 101,
#     "height": 180.0,
#     "name": "大帅哥",
#     "has_money": True,
#     "ads": None,
#     "address": ("郑州", "新乡"),
#     "hobby": {"足球", "篮球"},
#     "born": datetime.today()
# }]
#
# class MyEncoder(json.JSONEncoder):
#     def default(self, o):
#         print(o, type(o))
#         if isinstance(o, set):
#             return list(o)
#         elif isinstance(o, datetime):
#             return o.strftime("%Y-%m-%d %H:%M:%S")
#         return "are you ok?"
#
# obj_str = json.dumps(obj, cls=MyEncoder)
# print(obj_str)


# from datetime import datetime
# class MYDecoder(json.JSONDecoder):
#     def decode(self, s):
#         datas = json.loads(s)
#         for data in datas:
#             if "born" in data:
#                 data["born"] = datetime.strptime(data["born"], "%Y-%m-%d %H:%M:%S")
#             if "hobby" in data:
#                 data["hobby"] = set(data["hobby"])
#         return datas
#
#
# obj_str = '[{"id": 101, "born": "2024-06-25 14:33:39", "hobby":["篮球", "足球"]}]'
# obj = json.loads(obj_str, cls=MYDecoder)
# print(obj)
# for data in obj:
#     for k, v in data.items():
#         print(k, v, type(v))


# 魔法函数 __函数名__
# __new__  __init__ __str__ __del__ __enter__ __exit__
# __bases__ __doc__ __name__ __class__ __dir__ __sizeof__
# __gt__  __ge__ __lt__  __le__ __eq__ __ne__

# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def __gt__(self, other):
#         return self.age > other.age
#
#     def __ge__(self, other):
#         return self.age >= other.age
#
#     def __lt__(self, other):
#         return self.age < other.age
#
#     def __le__(self, other):
#         return self.age <= other.age
#
#
# p1 = Person("a", 20)
# p2 = Person("b", 30)
# print(p1 >= p2, p1 < p2)
# print(max(p1, p2))
# print(max(p1, p2, key=lambda e:e.age).name)


#
# class SingleManage:
#     """单利类"""
#     def __new__(cls, *args, **kwargs):
#         if not hasattr(SingleManage, "instance"):
#             setattr(SingleManage, "instance", super().__new__(cls))
#             print(f"创建了实例")
#         return getattr(SingleManage, "instance")
#
#     def __init__(self):
#         print(f"初始化实例{id(self)}")
#
#     def init_datas(self, *args):
#         self.datas = [i for i in args]
#
#     def __str__(self):
#         return f"我是单利类"
#
#     def __del__(self):
#         print(f"析构执行了")
#
#
# sm = SingleManage()
# sm.init_datas(10, 20, 30)
#
# sm2 = SingleManage()
# print(sm2.datas)
#
# print(sm, sm2)
#
# print(SingleManage.__bases__,SingleManage.__doc__, SingleManage.__name__, SingleManage.__class__)
# print(SingleManage.__dir__, SingleManage.__sizeof__)
#


# ascii、unicode  字符集合（收纳字符）
# 计算机刚开始 ascii 是128个字符（2^7）   a-z A-Z 0-9 + - * / ? = | \ ....
# 计算机完善 ascii 是256个字符(2^8)   a-z A-Z 0-9 + - * / ? = | \ ....  + ....
# 计算机流行到了全球 unicode(十几万个字符)  ........
# 大神文明 abcd(亿亿个字符) .....

# 为了表示字符需要使用字节编码（使用什么长度，什么格式进行编码utf-8、utf-16）
# 万国码 utf8
# 东亚码 gbk

